/**
 * var声明的bug
 * var声明没有块级作用域的概念，var声明的变量会在整个function中提升到顶部赋值
 * let和const可以针对块级作用域赋值，不会提升，只在运行到声明语句时才会生效
 */


// var_fc()    //一次就会停止，i会被覆盖为字符串变量
// let_fc()    //正常

// var_new()
let_new()

function var_fc(){
    for(var i = 0; i < 5; i++){
        console.log(i)
    
        if(true){
            var i = "i is str"
            console.log(i)
        }
    }
}

function let_fc(){
    for(let i = 0; i < 5; i++){
        console.log(i)
        
        if(true){
            let i = "i is str"
            console.log(i)
        }
    }
}

var a = "a is global"
function var_new(){
    console.log(a)  // undefined
    var a = "i is var"
    console.log(a)
}

let b = "b is global"
function let_new(){
    console.log(b)  // b is not define 报错，程序终止
    let b = "i is var"
    console.log(b)
}